package org.example.repository.authorization.resource;

import com.bianmaba.spring.data.jpa.repository.support.ExtendedRepository;
import org.example.bean.entity.authorization.Resource;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * Created by cwx183898 on 2017/8/9.
 */
@Repository
public interface ResourceRepository extends ExtendedRepository<Resource, String> {

    Resource findByUrl(String url);


    @Query(value = "select role.name as name from  system_role role  join system_resource_ref_role rr on role.id=rr.role_id  join system_resource resource on rr.resource_id=resource.id " +
            "                where resource.url=:resource", nativeQuery = true)
    List<String> findRoleNames(@Param("resource") String resource);
}
